package org.ru.mse10.cvis.entity.cv.custom;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Transient;

import org.ru.mse10.cvis.util.CommonUtil;

/**
 * The Class IntegerCustomFieldValue.
 */
@Entity
@DiscriminatorValue("INTEGER")
public class IntegerCustomFieldValue extends CustomFieldValue {

	/**
	 * Gets the integer value.
	 * 
	 * @return the integer value
	 */
	@Transient
	public Integer getIntegerValue() {
		if (!CommonUtil.isEmpty(getValue())) {
			try {
				int parseInt = Integer.parseInt(getValue());
				return parseInt;
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	/**
	 * Sets the integer value.
	 * 
	 * @param integer
	 *            the new integer value
	 */
	public void setIntegerValue(Integer integer) {
		String stringValue = null;
		if (!CommonUtil.isEmpty(integer)) {
			stringValue = integer.toString();
		}
		setValue(stringValue);
	}
}
